package com.gxgeek.javabasic.Threads;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author gaoxing
 * @create 2017-10-27 上午10:48
 */
public class ThreadExample12 {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);
        List<Future> list = new ArrayList<>();
        for (int i = 0; i <3 ; i++) {
            Future<String> future = threadPool.submit(()->{
                Thread.sleep(2000);
                return "Hello World";
            });
            list.add(future);
        }



        System.out.println("等待结果");
        try {
            System.out.println("返回结果为:" );
//            System.out.println("返回结果为:" + future.get());
            for (int i = 0; i < list.size(); i++) {
                System.out.println(list.get(i).get());
            }
//            list.forEach((f)-> );
//            System.out.println("返回结果为:" + future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
